package com.shuzijun.leetcode.editor.cn;

import java.util.*;

public class GroupAnagrams{
    public static void main(String[] args) {
         Solution solution = new GroupAnagrams().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public List<List<String>> groupAnagrams(String[] strs) {
        HashMap<String, List<String>> map = new HashMap<>();
        for (String str:strs
             ) {
            char[] array = str.toCharArray();
            Arrays.sort(array);
            String key = new String(array);
            List<String> list = map.getOrDefault(key, new ArrayList<>());
            list.add(str);
            map.put(key,list);
        }

        return new ArrayList<List<String>>(map.values());


    }
}
//leetcode submit region end(Prohibit modification and deletion)

}